package com.crm.customer.controller;

import com.crm.common.pojo.Linkman;
import com.crm.customer.service.LinkmanService;
import com.crm.global.exception.ExceptionEnum;
import com.crm.global.result.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "联系人管理")
@RestController
@RequestMapping("/linkman")
public class LinkmanController {
    @Autowired
    private LinkmanService linkmanService;

    @ApiOperation("查询所有联系人")
    @GetMapping("/findAll")
    @ApiImplicitParam(name = "customerId",value = "客户id",paramType = "query",required = true)
    public ResponseEntity<Message<List<Linkman>>> findAll(Long customerId) {
        List<Linkman> all = linkmanService.findAll(customerId);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS,all));
    }

   @ApiOperation("保存联系人")
    @PostMapping("/save")
    public ResponseEntity<Message<String>> save(@RequestBody  Linkman linkman) {
        linkmanService.saveOrUpdate(linkman);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

    @ApiOperation("更新联系人")
    @PostMapping("/update")
    public ResponseEntity<Message<String>> update(@RequestBody Linkman linkman) {
        linkmanService.saveOrUpdate(linkman);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

    @ApiOperation("删除联系人")
    @GetMapping("/delete")
    @ApiImplicitParam(name = "id",value = "联系人id",paramType = "query",required = true)
    public ResponseEntity<Message<String>> delete(Long id) {
        linkmanService.deleteById(id);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

}
